package com.zhouu.example.core.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 客服端工具类
 *
 * @author zhouu
 * @date 2021-02-24 23:30
 */
public class ServletUtil {

    /**
     * 获取 String 参数
     *
     * @param name 参数名称
     * @return String
     */
    public static String getParameter(String name) {
        return getRequest().getParameter(name);
    }

    /*public static String getParameter(String name, String defaultValue) {
        return
    }*/

    public static HttpServletRequest getRequest() {
        return getRequestAttributes().getRequest();
    }

    public static ServletRequestAttributes getRequestAttributes() {
        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }
}
